from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database

zhcxkj_center_listing_comprehensive_db= Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")


class T_allegro_listing:


    @staticmethod
    def t_allegro_listing(rule_code,source_id):
        if rule_code == 1:
            get_data = f"""
            select offer_id,sku,source_sku
            from test_zhcxkj_center_listing_comprehensive.t_allegro_listing_{source_id%8+1}
            where source_id = %s
            and source_sku in %s
            """
        elif rule_code == 2:
            get_data = f"""
            select offer_id,sku,source_sku
            from test_zhcxkj_center_listing_comprehensive.t_allegro_listing_{source_id%8+1}
            where source_id = %s
            and offer_id in %s
            """
        elif rule_code == 3:
            get_data = f"""
            select offer_id,sku,source_sku
            from test_zhcxkj_center_listing_comprehensive.t_allegro_listing_{source_id%8+1}
            where source_id = %s
            and sku in %s
            """
        res = zhcxkj_center_listing_comprehensive_db.fetch_all_tuple(get_data,())

    @staticmethod
    def get_is_active_by_source_id_sku(source_id,sku):
        get_data = f"""
        select source_id,sku,ean
        from test_zhcxkj_center_listing_comprehensive.t_allegro_listing_{source_id%8+1}
        where sku = %s
        and source_id = %s
        and status =3
        """
        data = zhcxkj_center_listing_comprehensive_db.fetch_all_tuple(get_data,(sku,source_id))
        return data